<script language="javascript">
$(function(){
	roleSelectInit('{{.roles}}');
	DepartmentInit('{{.m.DepartmentId}}', {{.m.ExtendDepartment}});
	if (!$.AMUI.support.mutationobserver) {
      	$("#IsSuper,#Status,#Roles").trigger('changed.selected.amui');
    }
});
//角色下拉框初始化
function roleSelectInit(selecteds){
	var url = '{{urlfor "RoleController.DataList"}}';
	var $select =$("#Roles");
	$select.html('');
	$.post(url,{},function(re){
		if(re.code === 0){               
			var html=[];
			$(re.data).each(function(i,e){
				html.push('<option value="' + e.Id + '">' + e.Name + '</option>')
			});
			$select.html(html.join(''));
			//$select.selectpicker({liveSearch:true});
			$select.val(selecteds.split(','));
		}
		else{
			layer.alert("获取角色数据失败",{icon:2,title:'失败'})
		}
	});
}
//门店
function DepartmentInit(selecteds, extend_selecteds){
	var url = '{{urlfor "DepartmentController.DataGrid"}}';
	var $select = $("#DepartmentId");
	var $extend = $('#ExtendDepartment');
	$.post(url,{},function(re){
		if(re.aaData.length > 0){               
			var html=[]
			$(re.aaData).each(function(i,e){
				html.push('<option value="' + e.Id + '">' + e.Name + '</option>')
			});
			$select.html(html.join(''));
            $extend.html(html.join(''));
			$select.val(selecteds);
            extend_selecteds ? $extend.val(extend_selecteds.split(',')) : '';
		}
		else{
			layer.alert("获取门店数据失败",{icon:2,title:'失败'})
		}
	});
}
</script>